import { userAccountLogin } from '@/api/user.js'
export default {
  namespaced: true,
  // eslint-disable-next-line space-before-function-paren
  state() {
    return {
      profile: {
        name: '小花'
      }
    }
  },
  mutations: {
    // 更新用户信息
    // eslint-disable-next-line space-before-function-paren
    setUser(state, payload) {
      state.profile = payload
    },
    // eslint-disable-next-line space-before-function-paren
    clearProfile(state) {
      state.profile = {}
      // state.profile = null  不要写null，写了null, profile.token就报错了
    }
  },
  actions: {
    // eslint-disable-next-line space-before-function-paren
    async asyncSetUser(context, payload) {
      console.log(context, payload)
      // 调用接口发请求
      const res = await userAccountLogin(payload)
      context.commit('setUser', res.result)
    }
  }
}
